package com.pets.springboot_petshop.controller;


import com.pets.springboot_petshop.pojo.Result;
import com.pets.springboot_petshop.util.AliOssUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;
/**
 * @Author: wxk
 * @Email: 2089967794@qq.com
 * @Date: 2024/10/15 下午10:44 周二
 * @Description: 图片上传
 */
@RestController
@CrossOrigin(origins = "*")
public class FileUploadController {
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        //将文件内容存储在本地磁盘
        String originalFilename = file.getOriginalFilename();
        String filename = UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));
        /*file.transferTo(new File("D:\\期末uniapp\\后端\\files\\"+filename));*/
        String url = AliOssUtil.uploadFile(filename,file.getInputStream());
        return Result.success(url);
    }
}
